package fifth.static关键字.static相关应用;

public class 为对象自动编名 {
    public static void main(String[] args) {
        System.out.println(new Demo1().getName());
        System.out.println(new Demo1("KarkitChan").getName());
        System.out.println(new Demo1().getName());
        System.out.println(new Demo1("Odyssey").getName());
        System.out.println(new Demo1().getName());
    }
}

class Demo1 {
    private String name;
    private static int count;   // 所有对象共享此属性

    public Demo1() {
        count++;
        this.name = "DEMO_" + count;
    }

    public Demo1(String name) {
        this.name = name;
    }

    public String getName() {
        return this.name;
    }
}